import { Controller } from "../../mvc/core/Controller";
import { ITaskModule } from "../../../modules/interfaces/ITaskModule";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { DataEvent } from "../events/DataEvent";
import { EventName } from "../mvc/EventName";
import { TaskInfo } from "../model/TaskInfo";
import { GameController } from "../mvc/GameController";
import { STask } from "../../../Message/Game/STask";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { EGateCommand } from "../../../Message/Command/EGateCommand";
import { GameProxy } from "../mvc/GameProxy";
import { STaskRemove } from "../../../Message/Game/STaskRemove";
import { SAddPlayerTask } from "../../../Message/Game/SAddPlayerTask";
import { ETaskGroup } from "../../../Message/Game/ETaskGroup";
import { RolePlayer } from "../scene/player/entity/RolePlayer";
import { MsgManager } from "../manager/MsgManager";
import { Language } from "../../../extend/language/Language";
import { PulseSharedObject } from "../view/player/PulseSharedObject";
import { Alert } from "../../../com/mui/controls/Alert";
import { CheckBoxWin } from "../view/common/alertwins/CheckBoxWin";
import { TaskConfig } from "../resource/TaskConfig";
import { SoundManager } from "../../common/sound/SoundManager";
import { SoundTypeConst } from "../../common/sound/SoundTypeConst";
import { WindowEvent } from "../../component/window/WindowEvent";
import { TaskTargetInfo } from "../model/TaskTargetInfo";
import { GuideMallBuyModule } from "../../../modules/GuideMallBuyModule";
import { ItemData } from "../resource/info/ItemData";
import { Tooltip } from "../view/common/tooltip/Tooltip";
import { ObjCreate } from "../view/common/ObjCreate";
import { Global } from "../../../com/gengine/global/Global";
import { LayerManager } from "../manager/LayerManager";
import { GuideOptType } from "../rules/GuideOptType";
import { ECategory } from "../../../Message/Public/ECategory";
import { EProp } from "../../../Message/Public/EProp";
import { EntityType } from "../rules/EntityType";
import { GuideType } from "../rules/GuideType";
import { ETaskStatus } from "../../../Message/Game/ETaskStatus";
import { AIManager } from "../scene/ai/AIManager";
import { AIType } from "../scene/ai/AIType";
import { GameMapUtil } from "../scene/map/GameMapUtil";
import { GameConst } from "../../component/gconst/GameConst";
import { MapFileUtil } from "../scene/map/MapFileUtil";
import { WalkthroughWindow } from "../view/walkthrough/WalkthroughWindow";
import { Game } from "../Game";
import { SceneConfig } from "../resource/SceneConfig";
import { ENpcEffect } from "../../../Message/Public/ENpcEffect";
import { GameManager } from "../manager/GameManager";
import { ModuleType } from "../view/common/ModuleType";
import { SPlayerGuildInfo } from "../../../Message/Game/SPlayerGuildInfo";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { TransportNPCGuide } from "../view/transport/TransportNPCGuide";
import { ItemConfig } from "../resource/ItemConfig";
import { TaskRule } from "../rules/TaskRule";
import { HTMLUtil } from "../../../com/gengine/utils/HTMLUtil";
import { ColorConfig } from "../resource/ColorConfig";
import { EReward } from "../../../Message/Public/EReward";
import { IView } from "../../mvc/interfaces/IView";
import { TaskModule } from "../../../modules/TaskModule";
import { IGuideMallBuyModule } from "../../../modules/interfaces/IGuideMallBuyModule";
import { GButton } from "../../../com/mui/controls/GButton";
type int = number;
//class TaskController
    
    export  class TaskController extends Controller
    {
       

        /* internal  */onTaskListRes(arg1: Array<any>): void
        {
            if (_view != null) 
            {
                (_view as ITaskModule).myTaskListInit(arg1);
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.ServerBackTaskListRequest, arg1));
            return;
        }

        /* internal  */onTaskUpdate(arg1: Array<any>): void
        {
            if (_view != null) 
            {
                (_view as ITaskModule).updateTask(arg1);
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.ServerBackTaskUpdate, arg1));
            return;
        }

        /* internal  */onTaskAddRes(arg1: TaskInfo): void
        {
            if (_view != null) 
            {
                (_view as ITaskModule).myTaskAdd(arg1);
            }
            if (arg1 && arg1.endLevel > cache.role.entityInfo.level) 
            {
                GameController.gameui.getGameui().highlightWalkthroughIcon();
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.ServerBackTaskAdd, arg1));
            return;
        }

        /* internal  */onTaskDelRes(arg1: STask): void
        {
            if (_view != null) 
            {
                (_view as ITaskModule).myTaskDel(arg1.code);
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.ServerBackTaskDel, arg1));
            return;
        }

        /* internal  */onCanGetRefreshRes(arg1: Array<any>): void
        {
            if (_view != null) 
            {
                (_view as ITaskModule).canGetTaskRefresh(arg1);
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.ServerBackCanGetListRefresh, arg1));
            return;
        }

        /* internal  */onCanGetAddRes(arg1: Array<any>): void
        {
            if (_view != null) 
            {
                (_view as ITaskModule).canGetTaskAdd(arg1);
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.ServerBackCanGetListAdd, arg1));
            return;
        }

        /* internal  */onCanGetDelRes(arg1: int): void
        {
            if (_view != null) 
            {
                (_view as ITaskModule).canGetTaskDel(arg1);
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.ServerBackCanGetListDel, arg1));
            return;
        }

        /* internal  */onTaskRemoveRes(arg1: MessageBlock): void
        {
            var loc1=arg1.messageHead.command;
            switch (loc1) 
            {
                case EGateCommand._ECmdGateTaskRemove:
                {
                    GameProxy.taskProxy.removeTaskRes((arg1.messageBase as STaskRemove).taskCode);
                    break;
                }
            }
            return;
        }

        /* internal  */onAddPlayerTaskRes(arg1: MessageBlock): void
        {
            GameProxy.taskProxy.addCurrentTask(arg1.messageBase as SAddPlayerTask);
            return;
        }

        public onShowOrHideTrack(arg1: Boolean): void
        {
            if (_view != null) 
            {
                (_view as ITaskModule).onShowOrHideTrack(arg1);
            }
            return;
        }

        /* internal  */onTrackClick(arg1: DataEvent): void
        {
            GameController.taskTrack.onShowOrHideTrack(arg1.data);
            return;
        }

        /* internal  */onCancelTask(arg1: DataEvent): void
        {
            var loc1=arg1.data as TaskInfo;
            if (loc1) 
            {
                if (loc1.sTask.group == ETaskGroup._ETaskGroupRunBusiness) 
                {
                    if (RolePlayer.instance.fighting) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(20238));
                        return;
                    }
                }
                if (PulseSharedObject.isTodayNotTips(cache.guide.guideNotAlertCancel)) 
                {
                    this.onGiveUpHandler(Alert.OK, loc1, false);
                }
                else 
                {
                    Alert.extendObj = loc1;
                    Alert.alertWinRenderer = CheckBoxWin;
                    Alert.show(Language.getStringByParam(20239, "『" + TaskConfig.instance.getTaskName(loc1.sTask.code) + "』"), Language.getString(20055), Alert.OK | Alert.CANCEL, null, this.onGiveUpHandler);
                }
            }
            return;
        }

        /* internal  */onGiveUpHandler(arg1: int, arg2: TaskInfo, arg3: Boolean): void
        {
            if (arg1 == Alert.OK) 
            {
                if (arg2 != null) 
                {
                    GameProxy.taskProxy.delTaskReq(arg2.sTask.code);
                    SoundManager.instance.soundPlay(SoundTypeConst.GiveUpTask);
                }
            }
            if (arg3) 
            {
                PulseSharedObject.save(cache.guide.guideNotAlertCancel, true);
            }
            return;
        }

        /* internal  */onWindowShow(arg1: WindowEvent): void
        {
            _view.removeEventListener(WindowEvent.SHOW, this.onWindowShow);
            (_view as ITaskModule).myTaskListInit(cache.task.myTaskList);
            (_view as ITaskModule).canGetTaskAdd(cache.task.canGetTask);
            return;
        }

        
        {
            TaskController._spTooltipContainer = new Object /* flash.display.Sprite */();
            TaskController._point = new Object /* flash.geom.Point */();
        }

        /* internal  */showMailBuyGuild(arg1: TaskInfo, arg2: TaskTargetInfo): void
        {
            if (cache.guide.guideMailCount <= 2) 
            {
                if (this._guideBuyModule == null) 
                {
                    this._guideBuyModule = new GuideMallBuyModule();
                }
                this._guideBuyModule.show();
                this._guideBuyModule.updateData(arg2, arg1);
            }
            return;
        }

        /* internal  */showMailBuyAward(arg1: int): void
        {
            var loc1=new ItemData(arg1);
            if (!TaskController._toolTip) 
            {
                TaskController._toolTip = new Tooltip();
                TaskController._closeBtn = ObjCreate.createGButton("", TaskController._toolTip.width - 24, 4, 20, 18, null, "SmallCLoseBtn");
                TaskController._spTooltipContainer.addChild(TaskController._toolTip);
                TaskController._spTooltipContainer.addChild(TaskController._closeBtn);
            }
            TaskController._point.x = Global.stage.mouseX;
            TaskController._point.y = Global.stage.mouseY;
            TaskController._toolTip.data = loc1.getToolTipData();
            TaskController._spTooltipContainer.x = TaskController._point.x;
            TaskController._spTooltipContainer.y = TaskController._point.y;
            LayerManager.toolTipLayer.addChild(TaskController._spTooltipContainer);
            TaskController._closeBtn.x = TaskController._toolTip.width - 24;
            TaskController._closeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.closeTootipHandler);
            this.resetToolTipPosition();
            return;
        }

        /* internal  */resetToolTipPosition(): void
        {
            if (TaskController._spTooltipContainer.x > Global.stage.stageWidth - TaskController._spTooltipContainer.width - 6) 
            {
                TaskController._spTooltipContainer.x = TaskController._spTooltipContainer.x - TaskController._spTooltipContainer.width - 6;
            }
            var loc1=1;
            TaskController._spTooltipContainer.y = TaskController._spTooltipContainer.y - TaskController._spTooltipContainer.height - 6;
            if (TaskController._spTooltipContainer.y < 0) 
            {
                TaskController._spTooltipContainer.y = 0;
            }
            return;
        }

        /* internal  */closeTootipHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (TaskController._spTooltipContainer && TaskController._spTooltipContainer.parent) 
            {
                TaskController._spTooltipContainer.parent.removeChild(TaskController._spTooltipContainer);
            }
            return;
        }

        /* internal  */onTaskAutoPathReq(arg1: DataEvent): void
        {
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=null;
            var loc8=null;
            var loc9=null;
            var loc10=null;
            var loc11=null;
            var loc1=arg1.data.target as TaskTargetInfo;
            var loc2=arg1.data.task as TaskInfo;
            if (loc1.targetType != GuideOptType.GuideRunBuiness) 
            {
                if (loc1.targetType != GuideOptType.GuideShopBuy) 
                {
                    if (loc1.targetType != GuideOptType.GuideTaskBuyReward) 
                    {
                        if (loc1.targetType != GuideOptType.GuideApplyGuild) 
                        {
                            if (loc1.targetType == GuideOptType.GuideCycleCount || loc1.targetType == GuideOptType.GuideCycleTaskGet) 
                            {
                                if ((loc5 = cache.pack.backPackCache.getTypeItems(ECategory._ECategoryProp, EProp._EPropTaskLoopBook)).length > 0) 
                                {
                                    GameController.cycle.view.show();
                                }
                                else 
                                {
                                    MsgManager.showRollTipsMsg(Language.getString(20241));
                                }
                            }
                            else if (loc1.targetType != GuideOptType.GuideGuildTaskCount) 
                            {
                                if (loc1.targetType != GuideOptType.GuideCentralCount) 
                                {
                                    if (loc1.targetType != GuideOptType.GuideAttackLevel) 
                                    {
                                        if (loc1.targetType != GuideOptType.GuideMovieWeaponStrengthen) 
                                        {
                                            if (loc1.targetType != GuideOptType.GuideMovieRefreshPetGrowth) 
                                            {
                                                if (loc1.targetType != EntityType.Scene) 
                                                {
                                                    if (loc1.targetType != GuideOptType.GuideWalkthrough) 
                                                    {
                                                        if (loc1.targetType != GuideOptType.GuideDoNationalTreasure) 
                                                        {
                                                            if (loc2.sTask.guide & GuideType.Fly && !(loc2.status == ETaskStatus._ETaskStatusCanGet)) 
                                                            {
                                                                GameController.guide.clearGuideTimer();
                                                                cache.guide.flyGuide = true;
                                                                AIManager.onAIControl(loc1, AIType.AI_Convey);
                                                            }
                                                            else if (loc1.targetType != GuideOptType.GuideOpenHuntMap) 
                                                            {
                                                                if (loc1.targetType != GuideOptType.GuideBeginHunt) 
                                                                {
                                                                    if (loc1.targetType != GuideOptType.GuideLoveTask) 
                                                                    {
                                                                        if (loc1.targetType != GuideOptType.GuideFlowerTask) 
                                                                        {
                                                                            if (loc1.targetType != GuideOptType.GuidePetLifeStyleGet) 
                                                                            {
                                                                                if (loc1.targetType != GuideOptType.GuidePetLifeStyleDress) 
                                                                                {
                                                                                    if (GameMapUtil.isCopyMap(loc1.mapId)) 
                                                                                    {
                                                                                        if (loc1.mapId != GameConst.CrossSkyCityMapId) 
                                                                                        {
                                                                                            if (loc1.mapId != 900801) 
                                                                                            {
                                                                                                if (GameMapUtil.isCopyMap(MapFileUtil.mapID) && !cache.copy.isInboundlessSeaCopy() && !cache.copy.isInSunSeaCopy() && !GameMapUtil.curMapState.isCrossSea) 
                                                                                                {
                                                                                                    MsgManager.showRollTipsMsg(Language.getString(20244));
                                                                                                    return;
                                                                                                }
                                                                                            }
                                                                                            else if (!GameMapUtil.isMapById(900801)) 
                                                                                            {
                                                                                                if (GameController.crossBeach.isInCrossBeachActive) 
                                                                                                {
                                                                                                    Dispatcher.dispatchEvent(new DataEvent(EventName.CrossBeachShowEnterWindow));
                                                                                                }
                                                                                                else 
                                                                                                {
                                                                                                    MsgManager.showRollTipsMsg(Language.getString(20328));
                                                                                                }
                                                                                                return;
                                                                                            }
                                                                                        }
                                                                                        else if (!GameMapUtil.isMapById(GameConst.CrossSkyCityMapId)) 
                                                                                        {
                                                                                            if (GameController.skyCity.isInSkyCityActive) 
                                                                                            {
                                                                                                Dispatcher.dispatchEvent(new DataEvent(EventName.SkyCityShowEnterWindow));
                                                                                            }
                                                                                            else 
                                                                                            {
                                                                                                MsgManager.showRollTipsMsg(Language.getString(20327));
                                                                                            }
                                                                                            return;
                                                                                        }
                                                                                    }
                                                                                    if (loc2.sTask.group == ETaskGroup._ETaskGroupLoopBook && loc2.status == ETaskStatus._ETaskStatusHadCompleted) 
                                                                                    {
                                                                                        GameController.cycle.view.show();
                                                                                    }
                                                                                    AIManager.onAutoPathAIControl(loc1);
                                                                                }
                                                                                else 
                                                                                {
                                                                                    Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_PetLifeStyleDress));
                                                                                }
                                                                            }
                                                                            else 
                                                                            {
                                                                                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_PetLifeStyleGet));
                                                                            }
                                                                        }
                                                                        else 
                                                                        {
                                                                            Dispatcher.dispatchEvent(new DataEvent(EventName.FlowerOpenHandselFlower));
                                                                        }
                                                                    }
                                                                    else 
                                                                    {
                                                                        Dispatcher.dispatchEvent(new DataEvent(EventName.LoveTaskTarget, loc2));
                                                                    }
                                                                }
                                                                else if ((loc11 = cache.pack.backPackCache.getTypeItems(ECategory._ECategoryProp, EProp._EPropHuntShovel)).length > 0) 
                                                                {
                                                                    Dispatcher.dispatchEvent(new DataEvent(EventName.ItemUseReq, loc11[0] as ItemData));
                                                                }
                                                                else 
                                                                {
                                                                    MsgManager.showRollTipsMsg(Language.getString(20243));
                                                                }
                                                            }
                                                            else if ((loc10 = cache.pack.backPackCache.getTypeItems(ECategory._ECategoryProp, EProp._EPropHuntMap)).length > 0) 
                                                            {
                                                                Dispatcher.dispatchEvent(new DataEvent(EventName.ItemUseReq, loc10[0] as ItemData));
                                                            }
                                                            else 
                                                            {
                                                                MsgManager.showRollTipsMsg(Language.getString(20242));
                                                            }
                                                        }
                                                        else if (cache.nationalTrea.inActiveScene()) 
                                                        {
                                                            loc1 = cache.scene.getNearlyNationalTaskNPC(MapFileUtil.mapID);
                                                            if (loc1) 
                                                            {
                                                                AIManager.onAutoPathAIControl(loc1);
                                                            }
                                                        }
                                                        else 
                                                        {
                                                            Dispatcher.dispatchEvent(new DataEvent(EventName.NationalTreasureWindowShowReq));
                                                        }
                                                    }
                                                    else 
                                                    {
                                                        WalkthroughWindow.instance.show();
                                                    }
                                                }
                                                else 
                                                {
                                                    if (loc1.mapId == 900801) 
                                                    {
                                                        if (!GameMapUtil.isMapById(900801)) 
                                                        {
                                                            if (GameController.crossBeach.isInCrossBeachActive) 
                                                            {
                                                                Dispatcher.dispatchEvent(new DataEvent(EventName.CrossBeachShowEnterWindow));
                                                            }
                                                            else 
                                                            {
                                                                MsgManager.showRollTipsMsg(Language.getString(20328));
                                                            }
                                                            return;
                                                        }
                                                    }
                                                    AIManager.onAutoPathAIControl(loc1);
                                                }
                                            }
                                            else 
                                            {
                                                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_MovieRefreshPetGrowth));
                                            }
                                        }
                                        else 
                                        {
                                            Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_MovieWeaponStrengthen));
                                        }
                                    }
                                    else 
                                    {
                                        if ((loc6 = Game.sceneInfo.getBossRefreshInfoByLevel(loc1.x, loc1.y)) != null) 
                                        {
                                            loc7 = Game.sceneInfo;
                                        }
                                        else 
                                        {
                                            loc6 = (loc7 = SceneConfig.instance.getSceneInfo(400102)).getBossRefreshInfoByLevel(loc1.x, loc1.y);
                                        }
                                        if (loc6 != null) 
                                        {
                                            loc8 = new TaskTargetInfo();
                                            loc9 = loc6.getNormalBoss();
                                            loc8.id = loc9.code;
                                            loc8.name = loc9.name;
                                            loc8.x = loc6.px;
                                            loc8.y = loc6.py;
                                            loc8.targetType = EntityType.Boss;
                                            loc8.mapId = loc7.sMapDefine.mapId;
                                            loc8.mapName = loc7.sMapDefine.name;
                                            AIManager.onAutoPathAIControl(loc8);
                                        }
                                    }
                                }
                                else 
                                {
                                    AIManager.onAutoPathAIControl(cache.scene.getNpcByEffect(ENpcEffect._ENpcEffectCentralTask));
                                }
                            }
                            else 
                            {
                                AIManager.onAutoPathAIControl(cache.scene.getGuildTaskNPC()[0]);
                            }
                        }
                        else 
                        {
                            GameManager.instance.popupWindow(ModuleType.Guild);
                        }
                    }
                    else 
                    {
                        this.showMailBuyAward(loc1.id);
                    }
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuidOpenShopMall));
                    this.showMailBuyGuild(loc2, loc1);
                }
            }
            else if ((loc3 = cache.pack.backPackCache.getTypeItems(ECategory._ECategoryProp, EProp._EPropTaskSilverNote)).length > 0) 
            {
                loc4 = loc3[0];
                Dispatcher.dispatchEvent(new DataEvent(EventName.ItemUseReq, loc4));
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(20240));
            }
            return;
        }

        public onTaskGuideFlyReq(arg1: DataEvent): void
        {
            var loc1=arg1.data.target as TaskTargetInfo;
            var loc2=arg1.data.task as TaskInfo;
            if (loc1.targetType != GuideOptType.GuideAttackLevel) 
            {
                AIManager.onAIControl(loc1, AIType.AI_Convey);
            }
            return;
        }

        /* internal  */playerGuildInfoUpate(arg1: SPlayerGuildInfo): void
        {
            var loc1=null;
            var loc2=null;
            cache.guildTask.guildInfoInit = true;
            if (arg1 && arg1.guildId == 0) 
            {
                loc2 = cache.task.delCanGetTaskByGroup(ETaskGroup._ETaskGroupGuild);
                if (loc2 != null) 
                {
                    loc1 = cache.scene.delCanGetTask([loc2]);
                    NetDispatcher.dispatchCmd(ServerCommand.CanGetListDel, loc2.sTask.code);
                    NetDispatcher.dispatchCmd(EventName.NPC_Task_StatusUpdata, loc1);
                }
                loc2 = cache.task.delMyTaskByGroup(ETaskGroup._ETaskGroupGuild);
                if (loc2 != null) 
                {
                    loc1 = cache.scene.delTask([loc2]);
                    NetDispatcher.dispatchCmd(ServerCommand.TaskDel, loc2.sTask);
                    NetDispatcher.dispatchCmd(EventName.NPC_Task_StatusUpdata, loc1);
                }
            }
            return;
        }

        /* internal  */onGuildQuitHandler(arg1: DataEvent): void
        {
            var loc2=null;
            var loc1=cache.task.delCanGetTaskByGroup(ETaskGroup._ETaskGroupGuild);
            if (loc1 != null) 
            {
                loc2 = cache.scene.delCanGetTask([loc1]);
                NetDispatcher.dispatchCmd(ServerCommand.CanGetListDel, loc1.sTask.code);
                NetDispatcher.dispatchCmd(EventName.NPC_Task_StatusUpdata, loc2);
            }
            loc1 = cache.task.delMyTaskByGroup(ETaskGroup._ETaskGroupGuild);
            if (loc1 != null) 
            {
                loc2 = cache.scene.delTask([loc1]);
                NetDispatcher.dispatchCmd(ServerCommand.TaskDel, loc1.sTask);
                NetDispatcher.dispatchCmd(EventName.NPC_Task_StatusUpdata, loc2);
            }
            return;
        }

        /* internal  */onGuildDisbandHandler(arg1: DataEvent): void
        {
            var loc2=null;
            var loc1=cache.task.delCanGetTaskByGroup(ETaskGroup._ETaskGroupGuild);
            if (loc1 != null) 
            {
                loc2 = cache.scene.delCanGetTask([loc1]);
                NetDispatcher.dispatchCmd(ServerCommand.CanGetListDel, loc1.sTask.code);
                NetDispatcher.dispatchCmd(EventName.NPC_Task_StatusUpdata, loc2);
            }
            loc1 = cache.task.delMyTaskByGroup(ETaskGroup._ETaskGroupGuild);
            if (loc1 != null) 
            {
                loc2 = cache.scene.delTask([loc1]);
                NetDispatcher.dispatchCmd(ServerCommand.TaskDel, loc1.sTask);
                NetDispatcher.dispatchCmd(EventName.NPC_Task_StatusUpdata, loc2);
            }
            return;
        }

        /* internal  */onGotoTransportNpc(arg1: DataEvent): void
        {
            AIManager.onAutoPathAIControl(cache.scene.getNpcByEffect(ENpcEffect._ENpcEffectTransport));
            return;
        }

        /* internal  */onUseTransportFlushTokenHandler(arg1: DataEvent): void
        {
            if (cache.daily.transportInfo.needLevel > cache.role.entityInfo.level) 
            {
                MsgManager.showRollTipsMsg(Language.getStringByParam(20245, cache.daily.transportInfo.needLevel));
                return;
            }
            if (cache.daily.transportInfo.num == cache.daily.transportInfo.totalNum) 
            {
                MsgManager.showRollTipsMsg(Language.getString(20246));
                return;
            }
            if (!this._transportNPCGuide) 
            {
                this._transportNPCGuide = new TransportNPCGuide();
                this._transportNPCGuide.layer = LayerManager.windowLayer;
            }
            if (this._transportNPCGuide.isHide) 
            {
                this._transportNPCGuide.show();
            }
            this._transportNPCGuide.updateData(cache.scene.getNpcByEffect(ENpcEffect._ENpcEffectTransport));
            return;
        }

        /* internal  */onTaskQuickComAndEnd(arg1: DataEvent): void
        {
            var loc1=arg1.data as TaskInfo;
            this.onTaskQuickComAndEndImpl(loc1);
            return;
        }

        /* internal  */onTaskQuickComAndEndImpl(arg1: TaskInfo): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=null;
            var loc5=0;
            var loc6=0;
            if (arg1 != null) 
            {
                if (PulseSharedObject.isTodayNotTips(cache.guide.guideNotAlertQuickCom + "_" + arg1.sTask.group)) 
                {
                    this.onQuickComAndEndAlert(Alert.OK, {"task": arg1, "itemCount": loc6}, false);
                }
                else 
                {
                    loc1 = "";
                    loc2 = ItemConfig.instance.getItemByType(ECategory._ECategoryProp, EProp._EPropQuickCompleteTask, -1, arg1.sTask.group);
                    loc3 = TaskRule.getQuickComGlodCost(arg1.sTask.group);
                    loc4 = TaskRule.getQuickComCostType(arg1.sTask.group);
                    loc5 = TaskRule.getQuickComCostTypeLevel(arg1.sTask.group);
                    if (loc2) 
                    {
                        loc1 = Language.getStringByParam(20247, HTMLUtil.addColor("【" + arg1.taskName + "】", arg1.taskNameColor), loc3, loc4, Language.getStringByParam(20249, "1") + HTMLUtil.addColor(loc2.item.name, ColorConfig.instance.getItemColor(loc2.item.color).color));
                        loc1 = loc1 + ("<br>" + HTMLUtil.addColor("(" + Language.getString(25300) + loc2.item.name + ")", "#00ff00"));
                        loc6 = cache.pack.backPackCache.getAllAoumtOfSameNameItem(loc2.item.name);
                        loc1 = loc1 + ("  " + HTMLUtil.addColor(Language.getStringByParam(25301, loc6 + ""), "#ffff00"));
                    }
                    else 
                    {
                        loc1 = Language.getStringByParam(20247, HTMLUtil.addColor("【" + arg1.taskName + "】", arg1.taskNameColor), "");
                    }
                    if (loc5 > cache.role.entityInfo.level) 
                    {
                        loc1 = loc1 + ("<br>" + HTMLUtil.addColor(Language.getString(20365) + Language.getStringByParam(20366, loc5), "#00ff00"));
                    }
                    Alert.buttonWidth = 100;
                    Alert.extendObj = {"task": arg1, "itemCount": loc6};
                    Alert.alertWinRenderer = CheckBoxWin;
                    Alert.show(loc1, Language.getString(20055), Alert.OK | Alert.CANCEL, null, this.onQuickComAndEndAlert);
                }
            }
            return;
        }

        /* internal  */onQuickComAndEndAlert(arg1: int, arg2: Object, arg3: Boolean): void
        {
            var loc3=0;
            var loc4=0;
            var loc1=arg2.task;
            var loc2=arg2.itemCount;
            if (arg1 == Alert.OK) 
            {
                if (loc2 == 0) 
                {
                    if (!((loc3 = TaskRule.getQuickComCostTypeLevel(loc1.sTask.group)) == 0) && loc3 <= cache.role.entityInfo.level) 
                    {
                        loc4 = TaskRule.getQuickComGlodCost(loc1.sTask.group);
                        if (cache.role.money.coin + cache.role.money.coinBind < loc4) 
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallAutoBuyCoin, loc4 - (cache.role.money.coin + cache.role.money.coinBind)));
                            MsgManager.showRollTipsMsg(Language.getString(20038));
                            return;
                        }
                    }
                }
                GameProxy.taskProxy.quickCompleteTask(loc1.sTask.code);
                if (loc1.sTask.group != ETaskGroup._ETaskGroupLoopBook) 
                {
                    if (cache.dialog.npcInfo) 
                    {
                        GameProxy.taskProxy.endTaskReq(cache.dialog.npcInfo.tnpc.npcId, loc1.sTask.code);
                        if (loc1.sTask.group == ETaskGroup._ETaskGroupSchool) 
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.SectarianTaskQuickEndRes));
                        }
                    }
                }
                else 
                {
                    GameProxy.cycle.taskEndReq();
                }
            }
            if (arg3) 
            {
                PulseSharedObject.save(cache.guide.guideNotAlertQuickCom + "_" + loc1.sTask.group, true);
            }
            return;
        }

        /* internal  */onTaskQuickComByItemReq(arg1: DataEvent): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=null;
            var loc1=arg1.data as ItemData;
            if (loc1) 
            {
                loc2 = cache.task.getTaskByGroup(loc1.effect, ETaskStatus._ETaskStatusNotCompleted);
                if (loc2 && loc2.length > 0) 
                {
                    loc4 = -1;
                    var loc6=0;
                    var loc7=loc2;
                    for(loc3 of loc7) 
                    {
                        if (!(loc3.color > loc4)) 
                        {
                            continue;
                        }
                        loc5 = loc3;
                        loc4 = loc3.color;
                    }
                    if (loc5) 
                    {
                        if (loc5.sTask.group != ETaskGroup._ETaskGroupCycle) 
                        {
                            if (loc5.sTask.group != ETaskGroup._ETaskGroupLoopBook) 
                            {
                                this.onTaskQuickComImpl(loc5);
                            }
                            else 
                            {
                                this.onTaskQuickComAndEndImpl(loc5);
                            }
                        }
                        else 
                        {
                            this.onTaskQuickEndImpl(loc5);
                        }
                    }
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(25302));
                }
            }
            return;
        }

        /* internal  */onTaskQuickComReq(arg1: DataEvent): void
        {
            var loc1=arg1.data as TaskInfo;
            this.onTaskQuickComImpl(loc1);
            return;
        }

        /* internal  */onTaskQuickComImpl(arg1: TaskInfo): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=null;
            var loc5=0;
            var loc6=0;
            if (arg1 != null) 
            {
                if (PulseSharedObject.isTodayNotTips(cache.guide.guideNotAlertQuickCom + "_" + arg1.sTask.group)) 
                {
                    this.onQuickComAlert(Alert.OK, {"task": arg1, "itemCount": 0}, false);
                }
                else 
                {
                    loc1 = "";
                    loc2 = ItemConfig.instance.getItemByType(ECategory._ECategoryProp, EProp._EPropQuickCompleteTask, -1, arg1.sTask.group);
                    loc3 = TaskRule.getQuickComGlodCost(arg1.sTask.group);
                    loc4 = TaskRule.getQuickComCostType(arg1.sTask.group);
                    loc5 = TaskRule.getQuickComCostTypeLevel(arg1.sTask.group);
                    if (loc2) 
                    {
                        loc6 = cache.pack.backPackCache.getAllAoumtOfSameNameItem(loc2.item.name);
                        loc1 = Language.getStringByParam(20247, HTMLUtil.addColor("【" + arg1.taskName + "】", arg1.taskNameColor), loc3, loc4, Language.getStringByParam(20249, "1") + HTMLUtil.addColor(loc2.item.name, ColorConfig.instance.getItemColor(loc2.item.color).color));
                        loc1 = loc1 + ("<br>" + HTMLUtil.addColor("(" + Language.getString(25300) + loc2.item.name + ")", "#00ff00"));
                        loc1 = loc1 + ("  " + HTMLUtil.addColor(Language.getStringByParam(25301, loc6 + ""), "#ffff00"));
                    }
                    else 
                    {
                        loc1 = Language.getStringByParam(20247, HTMLUtil.addColor("【" + arg1.taskName + "】", arg1.taskNameColor), loc3, loc4, "");
                    }
                    if (loc5 > cache.role.entityInfo.level) 
                    {
                        loc1 = loc1 + ("<br>" + HTMLUtil.addColor(Language.getString(20365) + Language.getStringByParam(20366, loc5), "#00ff00"));
                    }
                    Alert.buttonWidth = 100;
                    Alert.extendObj = {"task": arg1, "itemCount": loc6};
                    Alert.alertWinRenderer = CheckBoxWin;
                    Alert.show(loc1, Language.getString(20055), Alert.OK | Alert.CANCEL, null, this.onQuickComAlert);
                }
            }
            return;
        }

        /* internal  */onQuickComAlert(arg1: int, arg2: Object, arg3: Boolean): void
        {
            var loc3=0;
            var loc4=0;
            var loc1=arg2.task;
            var loc2=arg2.itemCount;
            if (arg1 == Alert.OK) 
            {
                if (loc2 == 0) 
                {
                    if (!((loc3 = TaskRule.getQuickComCostTypeLevel(loc1.sTask.group)) == 0) && loc3 <= cache.role.entityInfo.level) 
                    {
                        loc4 = TaskRule.getQuickComGlodCost(loc1.sTask.group);
                        if (cache.role.money.coin + cache.role.money.coinBind < loc4) 
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallAutoBuyCoin, loc4 - (cache.role.money.coin + cache.role.money.coinBind)));
                            MsgManager.showRollTipsMsg(Language.getString(20038));
                            return;
                        }
                    }
                }
                GameProxy.taskProxy.quickCompleteTask(loc1.sTask.code);
                if (loc1.sTask.group == ETaskGroup._ETaskGroupLoopBook) 
                {
                    GameProxy.cycle.taskEndReq();
                }
            }
            if (arg3) 
            {
                PulseSharedObject.save(cache.guide.guideNotAlertQuickCom + "_" + loc1.sTask.group, true);
            }
            return;
        }

        /* internal  */onTaskQuickEndReq(arg1: DataEvent): void
        {
            var loc1=arg1.data as TaskInfo;
            this.onTaskQuickEndImpl(loc1);
            return;
        }

        /* internal  */onTaskQuickEndImpl(arg1: TaskInfo): void
        {
            var loc1=0;
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=null;
            var loc6=0;
            var loc7=0;
            if (arg1) 
            {
                if (PulseSharedObject.isTodayNotTips(cache.guide.guideNotAlertQuickEnd + "_" + arg1.sTask.group)) 
                {
                    this.onCentralTaskEndAlert(Alert.OK, {"task": arg1, "itemCount": 0}, false);
                }
                else if (arg1.sTask.group != ETaskGroup._ETaskGroupCycle) 
                {
                    GameProxy.taskProxy.endTaskReq(arg1.sTask.endNpc, arg1.sTask.code);
                }
                else 
                {
                    loc1 = cache.daily.getCycleLocal();
                    if (loc1 != 0) 
                    {
                        loc1 = 10 - cache.daily.getCycleLocal() + 1;
                    }
                    else 
                    {
                        loc1 = 1;
                    }
                    loc2 = "";
                    loc3 = ItemConfig.instance.getItemByType(ECategory._ECategoryProp, EProp._EPropQuickCompleteTask, -1, arg1.sTask.group);
                    loc4 = TaskRule.getQuickComGlodCost(arg1.sTask.group, loc1);
                    loc5 = TaskRule.getQuickComCostType(arg1.sTask.group);
                    loc6 = TaskRule.getQuickComCostTypeLevel(arg1.sTask.group);
                    if (loc3) 
                    {
                        loc7 = cache.pack.backPackCache.getAllAoumtOfSameNameItem(loc3.item.name);
                        loc2 = Language.getStringByParam(20248, loc1, loc4, loc5, Language.getStringByParam(20249, loc1 + "") + HTMLUtil.addColor(loc3.item.name, ColorConfig.instance.getItemColor(loc3.item.color).color));
                        loc2 = loc2 + ("<br>" + HTMLUtil.addColor("(" + Language.getString(25300) + loc3.item.name + ")", "#00ff00"));
                        loc2 = loc2 + ("  " + HTMLUtil.addColor(Language.getStringByParam(25301, loc7 + ""), "#ffff00"));
                    }
                    else 
                    {
                        loc2 = Language.getStringByParam(20248, loc1, loc1 * 3, "");
                    }
                    if (loc6 > cache.role.entityInfo.level) 
                    {
                        loc2 = loc2 + ("<br>" + HTMLUtil.addColor(Language.getString(20365) + Language.getStringByParam(20366, loc6), "#00ff00"));
                    }
                    Alert.buttonWidth = 100;
                    Alert.alertWinRenderer = CheckBoxWin;
                    Alert.extendObj = {"task": arg1, "itemCount": loc7};
                    Alert.show(loc2, Language.getString(20055), Alert.OK | Alert.CANCEL, null, this.onCentralTaskEndAlert);
                }
            }
            return;
        }

        /* internal  */onCentralTaskEndAlert(arg1: int, arg2: Object, arg3: Boolean): void
        {
            var loc3=0;
            var loc4=0;
            var loc5=0;
            var loc1=arg2.task;
            var loc2=arg2.itemCount;
            if (arg1 == Alert.OK) 
            {
                if (!((loc3 = TaskRule.getQuickComCostTypeLevel(loc1.sTask.group)) == 0) && loc3 <= cache.role.entityInfo.level) 
                {
                    if ((loc4 = cache.daily.getCycleLocal()) != 0) 
                    {
                        loc4 = 10 - cache.daily.getCycleLocal() + 1;
                    }
                    else 
                    {
                        loc4 = 1;
                    }
                    if ((loc4 = loc4 - loc2) >= 1) 
                    {
                        loc5 = TaskRule.getQuickComGlodCost(loc1.sTask.group, loc4);
                        if (cache.role.money.coin + cache.role.money.coinBind < loc5) 
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallAutoBuyCoin, loc5 - (cache.role.money.coin + cache.role.money.coinBind)));
                            MsgManager.showRollTipsMsg(Language.getString(20038));
                            return;
                        }
                    }
                }
                GameProxy.centralTask.endCycleTask(0, loc1.sTask.code, true);
            }
            if (arg3) 
            {
                PulseSharedObject.save(cache.guide.guideNotAlertQuickEnd + "_" + loc1.sTask.group, true);
            }
            return;
        }

        /* internal  */onTaskGuildEndHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data.task;
            var loc2=arg1.data.count;
            var loc3=arg1.data.maxCount;
            if (loc2 != loc3) 
            {
                if (cache.dialog.npcInfo && !cache.scene.isGuildTaskNPC(cache.dialog.npcInfo.tnpc.npcId)) 
                {
                    Alert.buttonWidth = 100;
                    Alert.showCloseBtn = true;
                    Alert.okLabel = Language.getString(21020);
                    Alert.show(Language.getStringByParam(21021, HTMLUtil.addColor(loc1.rewardExp + "", "#ff00ff"), HTMLUtil.addColor(loc1.getRewardType(EReward._ERewardContribution) + "", "#ff00ff")) + Language.getStringByParam(21022, HTMLUtil.addColor(loc3 - loc2 + "", "#00ff00")), Language.getString(20055), Alert.OK, null, this.onGuildTaskEndAlertHandler);
                }
            }
            else 
            {
                Alert.buttonWidth = 100;
                Alert.show(Language.getStringByParam(21021, HTMLUtil.addColor(loc1.rewardExp + "", "#ff00ff"), HTMLUtil.addColor(loc1.getRewardType(EReward._ERewardContribution) + "", "#ff00ff")), Language.getString(20055), Alert.OK);
            }
            return;
        }

        /* internal  */onGuildTaskEndAlertHandler(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                AIManager.onAIControl(cache.scene.getNearlyGuildNPC(), AIType.AI_Convey);
            }
            return;
        }

        /* internal  */taskRewardDobuleReqHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as TaskInfo;
            if (loc1 == null) 
            {
                return;
            }
            var loc2={"task": loc1, "itemCount": cache.role.money.gold};
            if (PulseSharedObject.isTodayNotTips(cache.guide.guideNotAlertDobuleReward + "_doubleReward")) 
            {
                this.onDoubleRewardAlert(Alert.OK, loc2, false);
                return;
            }
            var loc3=Language.getStringByParam(80482, loc1.sTask.reserve1.toString());
            Alert.buttonWidth = 100;
            Alert.extendObj = loc2;
            Alert.alertWinRenderer = CheckBoxWin;
            Alert.show(loc3, Language.getString(20055), Alert.OK | Alert.CANCEL, null, this.onDoubleRewardAlert);
            return;
        }

        /* internal  */onDoubleRewardAlert(arg1: int, arg2: Object, arg3: Boolean): void
        {
            if (arg3) 
            {
                PulseSharedObject.save(cache.guide.guideNotAlertDobuleReward + "_doubleReward", true);
            }
            if (arg1 != Alert.OK) 
            {
                return;
            }
            var loc1;
            if ((loc1 = arg2["task"] as TaskInfo) == null) 
            {
                return;
            }
            GameProxy.taskProxy.endTaskReq(loc1.sTask.endNpc, loc1.sTask.code, 2);
            return;
        }

        protected /* override */ initView(): IView
        {
            var loc1=new TaskModule();
            loc1.addEventListener(EventName.TrackClick, this.onTrackClick);
            loc1.addEventListener(EventName.CancelTask, this.onCancelTask);
            loc1.addEventListener(WindowEvent.SHOW, this.onWindowShow);
            return loc1;
        }

        protected /* override */ initServer(): void
        {
            NetDispatcher.addCmdListener(ServerCommand.TaskListRes, this.onTaskListRes);
            NetDispatcher.addCmdListener(ServerCommand.TaskUpdate, this.onTaskUpdate);
            NetDispatcher.addCmdListener(ServerCommand.TaskAdd, this.onTaskAddRes);
            NetDispatcher.addCmdListener(ServerCommand.TaskDel, this.onTaskDelRes);
            NetDispatcher.addCmdListener(ServerCommand.CanGetListRefresh, this.onCanGetRefreshRes);
            NetDispatcher.addCmdListener(ServerCommand.CanGetListAdd, this.onCanGetAddRes);
            NetDispatcher.addCmdListener(ServerCommand.CanGetListDel, this.onCanGetDelRes);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateTaskRemove, this.onTaskRemoveRes);
            NetDispatcher.addCmdListener(ServerCommand.GuildUpdateInfo, this.playerGuildInfoUpate);
            Dispatcher.addEventListener(EventName.TaskAutoPathReq, this.onTaskAutoPathReq);
            Dispatcher.addEventListener(EventName.TaskGuideFlyReq, this.onTaskGuideFlyReq);
            Dispatcher.addEventListener(EventName.GuildQuitSuccess, this.onGuildQuitHandler);
            Dispatcher.addEventListener(EventName.GuildDisbandSuccess, this.onGuildDisbandHandler);
            Dispatcher.addEventListener(EventName.GoToTransportNPC, this.onGotoTransportNpc);
            Dispatcher.addEventListener(EventName.UseTransportFlushToken, this.onUseTransportFlushTokenHandler);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateAddPlayerTask, this.onAddPlayerTaskRes);
            Dispatcher.addEventListener(EventName.TaskQuickComReq, this.onTaskQuickComReq);
            Dispatcher.addEventListener(EventName.TaskQuickComByItem, this.onTaskQuickComByItemReq);
            Dispatcher.addEventListener(EventName.TaskQuickComAndEndReq, this.onTaskQuickComAndEnd);
            Dispatcher.addEventListener(EventName.TaskCancelTask, this.onCancelTask);
            Dispatcher.addEventListener(EventName.TaskQuickEndReq, this.onTaskQuickEndReq);
            Dispatcher.addEventListener(EventName.TaskGuildEnd, this.onTaskGuildEndHandler);
            Dispatcher.addEventListener(EventName.TaskRewardDoubleReq, this.taskRewardDobuleReqHandler);
            return;
        }

        private /* var */_guideBuyModule: IGuideMallBuyModule;

        private static /* var */_toolTip: Tooltip;

        private static /* var */_closeBtn: GButton;

        private static /* var */_spTooltipContainer: Object /* flash.display.Sprite */;

        private static /* var */_point: Object /* flash.geom.Point */;

        private /* var */_transportNPCGuide: TransportNPCGuide;
    }
